package com.healthtop.web;

import com.healthtop.common.HttpMessageResult;
import com.healthtop.common.Page;
import com.healthtop.common.Views;
import com.healthtop.dao.XsUserDao;
import com.healthtop.dto.XsUserDto;
import com.healthtop.service.DIYService;
import com.healthtop.service.XsUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/xsUser")
public class XsUserController {

    @Autowired
    private XsUserService xsUserService;

    @Autowired
    private DIYService diyService;

    /**
     *获取有这个权限的用户
     * @param roleId
     * @return
     */
    @RequestMapping("/selectUserByRoleId")
    @ResponseBody
    public List<Map> selectUserByRoleId(long roleId){
        return xsUserService.selectUserByRoleId(roleId);
    }

    /**
     * 判断该账号有没有人使用
     * @param userName
     * @return
     */
    @RequestMapping("/userNameIsNull")
    @ResponseBody
    public boolean userNameIsNull(String userName,Long userId){
        return xsUserService.userNameIsNull(userName,userId);
    }

    /**
     * 判断该手机号有没有用户使用
     * @param phoneNum
     * @return
     */
    @RequestMapping("/phoneNumIsNull")
    @ResponseBody
    public boolean phoneNumIsNull(String phoneNum,Long userId){
        return xsUserService.phoneNumIsNull(phoneNum,userId);
    }

    /**
     * 进入账号的修改/新增
     * @param xsUserDto
     * @return
     */
    @RequestMapping("/forward")
    public String forward(XsUserDto xsUserDto){
        xsUserService.forward(xsUserDto);
        return Views.XS_USER_FORM;
    }

    /**
     * 新增/修改账号
     * @param xsUserDto
     * @return
     */
    @RequestMapping("/operate")
    public String operate(XsUserDto xsUserDto){
        xsUserService.operate(xsUserDto);
        return Views.REDIRECT_XS_USER_LIST;
    }

    /**
     * 删除账号
     * @param xsUserDto
     * @return
     */
    @RequestMapping("/delete")
    public String delete(XsUserDto xsUserDto){
        xsUserService.delete(xsUserDto);
        return Views.REDIRECT_XS_USER_LIST;
    }

    /**
     * 获取账号列表
     * @param page
     * @return
     */
    @RequestMapping("/list")
    public String list(Page page){
        diyService.selectXsUserList(page);
        return Views.XS_USER_LIST;
    }


}
